--- @param extension Package
--- @param HY HY_Utility
--- @param U Utility
return function(extension, HY, U)
    local hy_aki_minoriko = General:new(extension, "hy_aki_minoriko", "ten_k", 4, 4, General.Female)

    local harvest_season = fk.CreateSkill {
        name = "harvest_season",
    }
    harvest_season:addEffect(fk.CardUsing, {
        can_trigger = function(self, event, target, player, data)
            return player:hasSkill(harvest_season.name) and (not data.card:isVirtual() or #data.card.subcards > 0) and data.card.trueName == "amazing_grace" and
                table.any(data:getAllTargets(), function(t)
                    return t ~= player
                end)
        end,
        on_cost = function(self, event, target, player, data)
            local room = player.room
            local targets = data:getAllTargets()
            table.removeOne(targets, player)
            local results = room:askToChoosePlayers(player, {
                targets = targets,
                min_num = 1,
                max_num = #targets,
                skill_name = harvest_season.name,
                prompt = "harvest_season_prompt:::" .. data.card:toLogString()
            })
            if #results > 0 then
                event:setCostData(self, results)
                return true
            end
        end,
        on_use = function(self, event, target, player, data)
            local room = player.room
            local targets = event:getCostData(self)
            data.nullifiedTargets = data.nullifiedTargets or {}
            table.insertTableIfNeed(data.nullifiedTargets, targets)
            room:setPlayerMark(player, "harvest_season_card", data.card:getEffectiveId())
            for _, t in ipairs(targets) do
                room:addTableMark(player, "harvest_season_targets", t.id)
            end
        end,
    })
    harvest_season:addEffect(fk.CardUseFinished, {
        is_delay_effect = true,
        can_trigger = function(self, event, target, player, data)
            return player:hasSkill(harvest_season.name) and data.card:getEffectiveId() and data.card:getEffectiveId() == player:getMark("harvest_season_card")
        end,
        on_use = function(self, event, target, player, data)
            local room = player.room
            local targetIds = player:getTableMark("harvest_season_targets")
            room:setPlayerMark(player, "harvest_season_card", 0)
            room:setPlayerMark(player, "harvest_season_targets", 0)
            local card = Fk:cloneCard("amazing_grace")
            local targets = table.filter(card:getAvailableTargets(player), function(t)
                return table.contains(targetIds, t.id) or t == player
            end)
            room:useCard({
                card = card,
                from = player,
                tos = targets,
            })
        end
    })
    harvest_season:addEffect(fk.AfterCardsMove, {
        can_trigger = function(self, event, target, player, data)
            if not player:hasSkill(harvest_season.name) then
                return false
            end
            for _, move in ipairs(data) do
                if move.to ~= player or move.toArea ~= Card.PlayerHand or move.skillName ~= "amazing_grace_skill" then
                    goto continue
                end
                for _, info in ipairs(move.moveInfo) do
                    local ids = event:getCostData(self) or {}
                    table.insertIfNeed(ids, info.cardId)
                    event:setCostData(self, ids)
                end
                ::continue::
            end
            return #(event:getCostData(self) or {}) > 0
        end,
        on_cost = Util.TrueFunc,
        on_use = function(self, event, target, player, data)
            local room = player.room
            for _, id in ipairs(event:getCostData(self)) do
                room:setCardMark(Fk:getCardById(id), "@@harvest_season-inhand", 1)
            end
        end
    })
    harvest_season:addEffect("maxcards", {
        exclude_from = function(self, player, card)
            if player:hasSkill(harvest_season.name) and card:getMark("@@harvest_season-inhand") > 0 then
                return true
            end
        end
    })

    local fill_granary = fk.CreateSkill {
        name = "fill_granary",
    }
    fill_granary:addEffect("viewas", {
        mute_card = false,
        pattern = "amazing_grace",
        card_filter = Util.FalseFunc,
        prompt = "fill_granary_prompt",
        view_as = function(self, player, cards)
            local subcards = table.filter(player:getCardIds("h"), function(id)
                return Fk:getCardById(id).trueName == "slash"
            end)
            if #subcards == 0 then
                return
            end
            local card = Fk:cloneCard("amazing_grace")
            card:addSubcards(subcards)
            return card
        end,
        before_use = function(self, player, use)
            player.room:setPlayerMark(player, "fill_granary_card", use.card:getEffectiveId())
        end,
        enabled_at_play = function(self, player)
            return player:usedSkillTimes(fill_granary.name) < 1
        end,
    })
    fill_granary:addEffect(fk.BeforeCardUseEffect, {
        can_refresh = function(self, event, target, player, data)
            return player:hasSkill(fill_granary.name) and data.card:getEffectiveId() and data.card:getEffectiveId() == player:getMark("fill_granary_card")
        end,
        on_refresh = function(self, event, target, player, data)
            local room = player.room
            room:setPlayerMark(player, "fill_granary_cards", room:getNCards(#data.tos))
        end
    })
    fill_granary:addEffect(fk.CardUseFinished, {
        is_delay_effect = true,
        can_trigger = function(self, event, target, player, data)
            return player:hasSkill(fill_granary.name) and data.card:getEffectiveId() and data.card:getEffectiveId() == player:getMark("fill_granary_card") and
                #player:getTableMark("fill_granary_cards") > 0 and
                #player:getTableMark("fill_granary_cards") ~= #data.extra_data.AGResult
        end,
        on_use = function(self, event, target, player, data)
            local room = player.room
            room:setPlayerMark(player, "fill_granary_card", 0)
            local max = #data.card.subcards + 1
            local cards = table.except(player:getTableMark("fill_granary_cards"), table.map(data.extra_data.AGResult, function(result)
                return result[2]
            end))
            max = max > #cards and #cards or max
            HY.ReplaceHandCardToTempNew(player, cards)
            local results = HY.AskForCard(player, 0, max, false, fill_granary.name, true, nil, "fill_granary_prompt_get:::" .. max)
            HY.ReverseHandCardFromTempNew(player)
            if #results > 0 then
                room:obtainCard(player, results, true, fk.ReasonPrey, player, fill_granary.name)
            end
        end
    })

    extension:loadSkillSkels { harvest_season, fill_granary }
    hy_aki_minoriko:addSkills { "harvest_season", "fill_granary" }

    Fk:loadTranslationTable {
        ["hy_aki_minoriko"] = "秋穰子",
        ["#hy_aki_minoriko"] = "丰饶",
        ["illustrator:hy_aki_minoriko"] = "aqoot",
        ["designer:hy_aki_minoriko"] = "黑曜人形",
        ["cv:hy_aki_minoriko"] = "",

        ["harvest_season"] = "丰季",
        [":harvest_season"] = "一名角色使用非虚拟的【五谷丰登】时，你可以令之对任意名其他角色无效。若如此做，此牌结算结束后你视为对这些角色与你使用【五谷丰登】。你通过【五谷丰登】获得的牌不计入手牌上限。",
        ["harvest_season_prompt"] = "丰季：你可以令%arg对任意名角色无效",
        ["@@harvest_season-inhand"] = "丰季",

        ["fill_granary"] = "盈库",
        [":fill_granary"] = "出牌阶段限一次，你可以将所有【杀】当作【五谷丰登】使用，此【五谷丰登】结算结束后，你获得至多X张未被获得的牌（X为转化牌数+1）。",
        ["fill_granary_prompt"] = "盈库：你可以将所有【杀】当【五谷丰登】使用",
        ["fill_granary_prompt_get"] = "盈库：你可以获得至多%arg张牌",
    }
end
